from abc import ABC, abstractmethod

from app.models import User
from app.WsCode import *


class Cmd(ABC):
    """命令执行接口"""

    @abstractmethod
    def exe(self, data=None):
        pass


class CmdRegister(Cmd):
    """注册命令"""

    def exe(self, data=None):
        user = User.objects.create()
        return {'code': USER_REGISTER_RESP, 'data': user.id}


class CmdLogin(Cmd):
    """登录命令"""

    def exe(self, data=None):
        user = User.objects.get(pk=data)
        user_data = {
            'id': user.id,
            'qq': user.qq,
            'wx': user.wx,
        }
        return {'code': USER_LOGIN_RESP, 'data': user_data}


class CmdCreatRole(Cmd):
    """创建角色命令"""

    def exe(self, data=None):
        user = User.objects.get(pk=data)
        user_data = {
            'id': user.id,
            'qq': user.qq,
            'wx': user.wx,
        }
        return {'code': USER_LOGIN_RESP, 'data': user_data}


CmdDict = {
    USER_REGISTER_REQ: CmdRegister,
    USER_LOGIN_REQ: CmdLogin,
}
"""命令字典"""
